package subject_set.weekly_competition.day10_16;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/10/16 11:05
 **/
public class Num4 {
    class Solution {
        public long countSubarrays(int[] nums, int minK, int maxK) {
            int ans = 0;
            List<Integer> list = new LinkedList<>();
            int len = nums.length;
            for(int i : nums) list.add(i);
            int i = 0, j = 1;
            while(i < len && j < len){
                List<Integer> ret = list.subList(i, j);

                Collections.sort(ret);
                for (Integer integer : ret) {
                    System.out.print(integer+" ");
                }
                System.out.println();
                if(ret.get(0) == minK && ret.get(ret.size()-1) == maxK){
                    ans++;
                    j++;
                }else if(ret.get(0) > minK && ret.get(ret.size()-1) < maxK){
                    j++;
                }else if(ret.get(0) < minK || ret.get(ret.size()-1) > maxK){
                    j++;
                    i = j;
                }
            }
            return ans;
        }
    }
}